package com.tester.yaa.exam002.threadLocal;

/**
 * @Aduthor yinanan
 * @ClassName ProducerThread
 * @Date 2022/12/11 18:41
 * @Description 生产者
 **/
public class ProducerThread implements Runnable {

    @Override
    public void run() {
        int num = 0;
        while (true) {
            num++;
            synchronized (Test.object) {
                //只生产10个包子
                if (Test.num == 10) {
                    System.exit(0);
                }
                if (Test.flag) {
                    System.out.println(Thread.currentThread().getName() + "生产了第" + num + "个包子");
                    Test.flag = false;
                    Test.num++;
                    try {
                        Test.object.wait();
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
        }
    }
}
